package com.zhy.skinchangenow.test

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.water.skin.SkinManager
import com.zhy.skinchangenow.R

class TestTagActivity : AppCompatActivity() {

    companion object {
        @JvmStatic
        fun jumpTo(context: Context) {
            context.startActivity(Intent(context, TestTagActivity::class.java))
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_tag)
        SkinManager.getInstance().register(this)
    }

    fun addNewView(view: View?) {
        //建议通过xml inflater
        val tv = TextView(this)
        tv.tag = "skin:item_text_color:textColor"
        tv.setTextColor(resources.getColorStateList(R.color.item_text_color))
        tv.text = "dymaic add!"
        (findViewById<View>(R.id.id_container) as ViewGroup).addView(tv)
        SkinManager.getInstance().injectSkin(tv)
    }

    override fun onDestroy() {
        super.onDestroy()
        SkinManager.getInstance().unregister(this)
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.menu_test_tag, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        val id = item.itemId
        return if (id == R.id.action_settings) {
            true
        } else super.onOptionsItemSelected(item)
    }
}